﻿using System.Collections.Generic;
using System.Linq;

namespace CoreLibrary.Email {

    public class EmailAddress {

        public string Name  { get; set; }
        public string Email { get; set; }

        public EmailAddress(string email) {
            Email = email;
            Asserts.NotBlank(email, "Email Address can not be empty.");
        }

        public EmailAddress(string name, string email) {
            Name  = name;
            Email = email.Trim();
            Asserts.NotBlank(email, "Email Address can not be empty.");
        }

        public static List<string> Parse(List<EmailAddress> emailAddresses) {
            return emailAddresses.Select(a => a.Email).ToList();
        }

        public static List<EmailAddress> Convert(IEnumerable<string> addresses) {
            return addresses.Where (address => !string.IsNullOrEmpty(address))
                            .Select(address => new EmailAddress(string.Empty,address))
                            .ToList();
        }

    }
}